package me.zhengjie.modules.finace_taxation.rest;

import com.alibaba.fastjson.JSONObject;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.finace_taxation.service.FtEnterpriseService;
import me.zhengjie.modules.finace_taxation.service.dto.FtEnterpriseDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtEnterpriseQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author 杨荣森
* @date 2021-06-29
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "ftEnterprise管理")
@RequestMapping("/api/ft/ftEnterprise")
public class FtEnterpriseController {

    private final FtEnterpriseService ftEnterpriseService;

    @GetMapping
    @Log("查询公司关联信息")
    @ApiOperation("查询公司关联信息")
//    @PreAuthorize("@el.check('ftEnterprise:list')")
    public ResponseEntity query(FtEnterpriseQueryParam query, Pageable pageable){
        return new ResponseEntity<>(ftEnterpriseService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增公司关联信息")
    @ApiOperation("新增公司关联信息")
//    @PreAuthorize("@el.check('ftEnterprise:add')")
    public JSONObject create(@Validated @RequestBody FtEnterpriseDto resources){
        JSONObject resObj = new JSONObject();
        int i = ftEnterpriseService.insert(resources);
        if (i > 0) {
            resObj.put("message", "添加成功! ");
            resObj.put("code", 200);
            resObj.put("success", true);
            return resObj;
        }
        resObj.put("message", "添加失败! ");
        resObj.put("code", 500);
        resObj.put("success", false);
        return resObj;
    }

    @PutMapping
    @Log("修改公司关联信息")
    @ApiOperation("修改公司关联信息")
//    @PreAuthorize("@el.check('ftEnterprise:edit')")
    public ResponseEntity update(@Validated @RequestBody FtEnterpriseDto resources){
        ftEnterpriseService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除公司关联信息")
    @ApiOperation("删除公司关联信息")
//    @PreAuthorize("@el.check('ftEnterprise:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        ftEnterpriseService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出ftEnterprise")
    @ApiOperation("导出ftEnterprise")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ftEnterprise:list')")
    public void download(HttpServletResponse response, FtEnterpriseQueryParam query) throws IOException {
        ftEnterpriseService.download(ftEnterpriseService.queryAll(query), response);
    }*/

}
